package com.imooc.corn;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @ClassName HelloScheduler
 * @Description TODO
 * @Author Wxg
 * @Date 2018/11/13 18:08
 * @Version 1.0
 */
public class CronScheduler {
    public static void main(String[] args) throws SchedulerException {
        JobDetail jobDetail = JobBuilder.newJob(CronJob.class)
                .withIdentity("myJob", "group1").build();


        CronTrigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("myTrigger", "group1")
                .startNow()
                .withSchedule(
                        CronScheduleBuilder.cronSchedule("* * * * * ? *"))
                .build();

        SchedulerFactory factory = new StdSchedulerFactory();
        org.quartz.Scheduler scheduler = factory.getScheduler();
        scheduler.start();

        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("Current Exec Time is : " + sdf.format(date));

        scheduler.scheduleJob(jobDetail, trigger);
    }
}
